﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Reflection;
using System.Text;
using System.Transactions;
using T.FAS.Runtime.Metadata.Entity;
using T.FAS.Runtime.Action.SPI;
using T.ServiceComponent.DAC.Service;
using T.ServiceComponent.DataAccessEx.Core;

namespace T.FAS.Runtime.Action.Dao
{
    public class ActionMetaDataELBDao : DaoService<ActionMetaData>
    {
        public const string MetaDataID = "ActionMetaData";
        public const string MetaDataName = "Action元数据";
        public override string TableName => "FAS_ActionMetaData";
        public override string IDColumnName => "ID";

        public override Dictionary<string, object> GetDataMapping(ActionMetaData data)
        {
            var mapping = base.GetDataMapping(data);
            mapping.Remove("ActionType");
            mapping.Add("ActionType", (int)data.ActionType);

            mapping.Remove("ReturnValueType");
            mapping.Add("ReturnValueType", (int)data.ReturnValueType);

            return mapping;
        }
        public ActionMetaDataELBDao() : base()
        {
            DBName = "TFAS";
        }
        public override Dictionary<string, PropertyInfo> GetColumns()
        {
            return DaoServiceExtension.GetAllColumns<ActionMetaData>(base.GetColumns());
        }
        public List<ActionMetaDataView> GetActionMetaDatasByRelatedMetaDataID(string metadataID)
        {
            var list = new List<ActionMetaDataView>();
            if (string.IsNullOrEmpty(metadataID))
                return list;
            List<IDbDataParameter> paramsList = new List<IDbDataParameter>();
            var sql = @"SELECT AM.ID,AM.Code,AM.Name,AM.LastModifyTime FROM FAS_ACTIONMETADATA AM WHERE 1=1 ";
            sql += $" and AM.RelatedMetaDataID = @metadataID";
            paramsList.Add(DB.MakeInParam("@metadataID", TDbDataType.VarChar, metadataID));
            var dataResult = DB.ExecuteDataSet(sql, paramsList.ToArray());
            return DataResultConvert.ConvertToActionMetaDataView(dataResult);
        }
    }
}
